using System.Collections;
using System.Collections.Generic;
using System;

//(c) 2011 VDZ
//made for Ludum Dare 22
//
//Licensed under Creative Commons Attribution-NonCommercial 3.0 Unported (CC BY-NC 3.0) 
//
//You are free:
//# to Share — to copy, distribute and transmit the work
//# to Remix — to adapt the work 
//
//Under the following conditions:
//# Attribution — You must attribute the work in the manner specified by the author or licensor
//      (but not in any way that suggests that they endorse you or your use of the work).
//# Noncommercial — You may not use this work for commercial purposes. 
//
//With the understanding that: 
//# Waiver — Any of the above conditions can be waived if you get permission from the copyright holder. 
//# Public Domain — Where the work or any of its elements is in the public domain under applicable law,
//      that status is in no way affected by the license. 
//# Other Rights — In no way are any of the following rights affected by the license:
//  * Your fair dealing or fair use rights, or other applicable copyright exceptions and limitations;
//  * The author's moral rights;
//  * Rights other persons may have either in the work itself or in how the work is used, such as publicity
//      or privacy rights.

public class Item {

    public enum ItemType
    {
        Food,
        Anime,
        Manga,
        Game
    }

    public string name;
    public string description;
    public int price;
    public ItemType type;
    public int healthEffect;
    public int depressionEffect;
    public int courageEffect;
    public int hopeEffect;
    public int usesLeft;
    public bool soldOut;
    public int releaseDate;

    public Item(string name, string description, ItemType type, int health, int depression, int courage, int hope, int price)
    {
        this.name = name;
        this.description = description;
        this.price = price;
        this.type = type;
        this.healthEffect = health;
        this.depressionEffect = depression;
        this.courageEffect = courage;
        this.hopeEffect = hope;
        this.soldOut = false;
        this.usesLeft = 1;
        this.releaseDate = 0;
    }

    public Item(string name, string description, ItemType type, int health, int depression, int courage, int hope, int price, int uses)
    {
        this.name = name;
        this.description = description;
        this.price = price;
        this.type = type;
        this.healthEffect = health;
        this.depressionEffect = depression;
        this.courageEffect = courage;
        this.hopeEffect = hope;
        this.soldOut = false;
        this.usesLeft = uses;
        this.releaseDate = 0;
    }

    public Item(string name, string description, ItemType type,
        int health, int depression, int courage, int hope, int price, int uses, int releaseDate)
    {
        this.name = name;
        this.description = description;
        this.price = price;
        this.type = type;
        this.healthEffect = health;
        this.depressionEffect = depression;
        this.courageEffect = courage;
        this.hopeEffect = hope;
        this.soldOut = false;
        this.usesLeft = uses;
        this.releaseDate = releaseDate;
    }

    public Item(Item it)
    {
        this.name = it.name;
        this.description = it.description;
        this.price = it.price;
        this.type = it.type;
        this.healthEffect = it.healthEffect;
        this.depressionEffect = it.depressionEffect;
        this.courageEffect = it.courageEffect;
        this.hopeEffect = it.hopeEffect;
        this.soldOut = false;
        this.usesLeft = it.usesLeft;
        this.releaseDate = it.releaseDate;
    }

    //Returns a random food from the set of items
    public static Item GetRandomFood(List<Item> items)
    {
        List<Item> food = new List<Item>();
        foreach (Item it in items)
        {
            if (it.type == ItemType.Food) food.Add(it);
        }

        if (food.Count == 0) return null; //No food!

        int randomNumber = new System.Random().Next(food.Count);

        return food[randomNumber];
    }

    //Uses an item; returns true if consumed, false if there's still uses left
    public bool Use()
    {
        usesLeft--;

        GameMain.gui.ItemFeedback(this);

        GameMain.ChangeHealth(healthEffect);
        if (depressionEffect != 0)
        {
            if (depressionEffect > 0)
            {
                GameMain.depression += depressionEffect;
                GameMain.gui.DepressionFeedback(depressionEffect);
            }
            else
            {
                GameMain.LoseDepression(-depressionEffect);
            }
        }
        GameMain.ChangeCourage(courageEffect);
        GameMain.ChangeHope(hopeEffect);
        
        if (usesLeft <= 0) return true;
        return false;
    }

    public bool Released() { if (GameMain.day < this.releaseDate) return false; return true; }
}
